<template>
  <el-dialog
    v-model="store.isModelShow"
    title="修改工作进度"
    v-on:open="changePath"
    :before-close="
      (done) => {
        afterClose();
        store.rowData = {};
        done();
      }
    "
  >
    <template #footer>
      <el-form :model="store.rowData" label-width="120px">
        <el-form-item label="ID">
          <el-input v-model="store.rowData.id" disabled />
        </el-form-item>
        <el-form-item label="code">
          <el-input v-model="store.rowData.code" disabled />
        </el-form-item>
        <el-form-item label="工作名称">
          <el-input v-model="store.rowData.task" />
        </el-form-item>

        <el-form-item label="开始时间">
          <el-col :span="8">
            <el-date-picker
              v-model="store.rowData.startTime"
              type="date"
              placeholder="Pick a date"
              style="width: 100%"
              format="YYYY-MM-DD"
              value-format="x"
            />
          </el-col>
          <el-col :span="3" class="text-center">
            <span class="text-gray-500">结束时间:</span>
          </el-col>
          <el-col :span="8">
            <el-date-picker
              v-model="store.rowData.endTime"
              placeholder="Pick a time"
              style="width: 100%"
              format="YYYY-MM-DD"
              value-format="x"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="工期">
          <el-input v-model="store.rowData.taskTime" />
        </el-form-item>
        <el-form-item label="前置任务">
          <el-input v-model="store.rowData.prepath" />
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button
          @click="
            afterClose();
            store.isModelShow = false;
            store.rowData = {};
          "
          >取消</el-button
        >
        <el-button type="primary" @click="submit">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { computed } from "@vue/reactivity";
import { onMounted, ref } from "vue";
import { store } from "../store.js";
import { GSTCID } from "@/controller/api.js";
import { remove } from "@/utils/method.js";
const props = defineProps({ submit: Function, afterClose: Function });
onMounted(() => {});
const taskTime = computed(() =>
  parseInt(
    (store.rowData.endTime - store.rowData.startTime) / (1000 * 3600 * 24)
  )
);
const changePath = (value, o) => {
  if (store.rowData.prepath) {
    console.log(store.rowData.prepath.split(","));
    const arr = store.rowData.prepath.split(",");
    if (arr.length > 0) {
      arr.map((item) => {
        state.update("config.chart.items." + GSTCID(item), (a) => {
          if (a.dependant.length > 0) remove(a.dependant, store.rowData.id);
          console.log(a);
          return a;
        });
      });
    }
  }
};
</script>
<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
.my-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
